﻿using System;
using System.Net;
using System.Runtime.InteropServices.Automation;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace XamlingCore.Infrastructure.Elevated
{
    public static class FileSystem
    {
        public static bool Copy(string source, string dest)
        {
            if(Exists(source))
            {
                using (dynamic fsoCom = AutomationFactory.CreateObject("Scripting.FileSystemObject"))
                {
                    dynamic file = fsoCom.GetFile(source);
                    file.Copy(dest);
                    return true;
                }    
            }
            return false;
        }

        public static void Delete(string target)
        {
            if(Exists(target))
            {
                using (dynamic fsoCom = AutomationFactory.CreateObject("Scripting.FileSystemObject"))
                {
                    fsoCom.DeleteFile(target);
                }
            }
        }

        public static bool Exists(string target)
        {
            using (dynamic fsoCom = AutomationFactory.CreateObject("Scripting.FileSystemObject"))
            {
                bool exists = fsoCom.FileExists(target);
                return exists;
            }
        }

    }
}
//            Dim fso, MyFile
//Set fso = CreateObject("Scripting.FileSystemObject")
//Set MyFile = fso.CreateTextFile("c:\testfile.txt", True)
//MyFile.WriteLine("This is a test.")
//MyFile.Close
//Set MyFile = fso.GetFile("c:\testfile.txt")
//MyFile.Copy ("c:\windows\desktop\test2.txt")

    